﻿<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:AEA.RSSFeedReader"
        xmlns:cmd="clr-namespace:System.Windows.Input;assembly=PresentationCore"
        x:Class="AEA.RSSFeedReader.MainApplication"
        x:Name="MainWindow"
        Title="RSS Feed Reader">

    <Window.Resources>
        <local:ChannelFeedDesignTime x:Key="DesignSource" />

        <!--Template for the feed items-->
        <DataTemplate x:Key="FeedItemTemplate">
            <StackPanel Orientation="Horizontal">
                <Image Margin="0,0,5,0"
                       Source="/Images/rss_icon_glass_gray12.PNG" />
                <TextBlock Text="{Binding Path=Title}"
                           Tag="{Binding}"
                           FontFamily="Calibri"
                           Foreground="#FFFFFFFF"
                           FontSize="14"
                           MouseLeftButtonUp="NavigateToItemFeed">
                    <TextBlock.ToolTip>
                        <TextBlock MaxWidth="400"
                                   TextWrapping="Wrap"
                                   Text="{Binding Path=Summary}" />
                    </TextBlock.ToolTip>
            		<TextBlock.ContextMenu>
            			<ContextMenu>
            				<MenuItem x:Name="CopyLinkCtxMenu"
                                      Header="_Copy Link"
                                      Click="CopyItemFeedLink"
                                      Tag="{Binding}" />
            			</ContextMenu>
            		</TextBlock.ContextMenu>
                </TextBlock>
            </StackPanel>
        </DataTemplate>

        <!--Template for the Channel feeds-->
        <HierarchicalDataTemplate x:Key="ChannelTemplate"
                                  ItemsSource="{Binding ItemFeeds, UpdateSourceTrigger=PropertyChanged}"
                                  ItemTemplate="{StaticResource FeedItemTemplate}">
            <StackPanel Orientation="Horizontal">
                <Image Source="/Images/rss_icon_glass12.PNG"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Stretch"
                       Margin="0,0,5,0"
                       Stretch="None" />
                <TextBlock Text="{Binding Path=ChannelTitle}"
                           Tag="{Binding}"
                           FontFamily="Calibri"
                           FontSize="16"
                           Foreground="#FF000000"
                           FontWeight="Bold">
                    <TextBlock.ToolTip>
                        <TextBlock MaxWidth="400"
                                   TextWrapping="Wrap"
                                   Text="{Binding Path=ChannelDescription}" />
                    </TextBlock.ToolTip>
                    <TextBlock.ContextMenu>
            			<ContextMenu>
            				<MenuItem x:Name="VisitSiteCtxMenu"
                                      Header="_Visit website"
                                      Click="VisitWebsite"
                                      Tag="{Binding}" />
                            <MenuItem x:Name="ReloadFeedsCtxMenu"
                                      Header="Reload Feeds"
                                      Click="ReloadChannelFeedItems"
                                      Tag="{Binding}" />
                            <Separator />                          
                            <MenuItem x:Name="DeleteCtxMenu"
                                      Header="Delete"
                                      Click="DeleteChannelFeed"
                                      Tag="{Binding}" />
            			</ContextMenu>
            		</TextBlock.ContextMenu>
                </TextBlock>
            </StackPanel>
        </HierarchicalDataTemplate>
    </Window.Resources>

    <Window.CommandBindings>
        <cmd:CommandBinding Command="New"
                            Executed="DoNewCommand" />
        <cmd:CommandBinding Command="local:Commands.ImportSettingsCommand"
                            Executed="DoImportSettingsCommand" />
        <cmd:CommandBinding Command="local:Commands.ExportSettingsCommand"
                            Executed="DoExportSettingsCommand"
                            CanExecute="CanExecuteExportSettingsCommand" />
        <cmd:CommandBinding Command="local:Commands.ExitCommand"
                            Executed="DoExitCommand" />
        <cmd:CommandBinding Command="local:Commands.DeleteAllChannelFeeds"
                            Executed="DoDeleteAllChannelFeeds"
                            CanExecute="CanExecuteDeleteAllChannelFeeds" />
        <cmd:CommandBinding Command="local:Commands.ReloadAllItemFeeds"
                            Executed="DoReloadAllItemFeeds"
                            CanExecute="CanExecuteReloadAllItemFeeds" />
    </Window.CommandBindings>

    <Window.InputBindings>
        <cmd:KeyBinding Command="local:Commands.ImportSettingsCommand"
                        Key="I"
                        Modifiers="Control" />
        <cmd:KeyBinding Command="local:Commands.ExportSettingsCommand"
                        Key="E"
                        Modifiers="Control" />
    </Window.InputBindings>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="2*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="25" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Menu Grid.ColumnSpan="2">
            <MenuItem Header="File">
                <MenuItem x:Name="AddFeedMenuItem"
                          Header="Add a new feed"
                          Command="New" />
                <MenuItem x:Name="ExportMenuItem"
                          Header="Export settings"
                          Command="local:Commands.ExportSettingsCommand"
                          InputGestureText="Ctrl+E" />
                <MenuItem x:Name="ImportMenuItem"
                          Header="Import settings"
                          Command="local:Commands.ImportSettingsCommand"
                          InputGestureText="Ctrl+I" />
                <Separator />
                <MenuItem x:Name="ReloadAllFeedsMenuItem"
                          Header="Reload all feeds"
                          Command="local:Commands.ReloadAllItemFeeds" />
                <MenuItem x:Name="DeleteAllFeedsMenuItem"
                          Header="Delete all feeds"
                          Command="local:Commands.DeleteAllChannelFeeds" />
                <Separator />
                <MenuItem x:Name="ExitMenuItem"
                          Header="_Exit"
                          Command="local:Commands.ExitCommand" />
            </MenuItem>
        </Menu>
        <!--TreeView containing the Channel Feeds-->
        <ContentControl HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        x:Name="FeedsTreeViewContent"
                        Grid.Row="1">
            <TreeView x:Name="Feeds"
                      ItemTemplate="{StaticResource ChannelTemplate}"
                      Grid.ColumnSpan="1"
                      Background="{StaticResource Background}"
                      ItemsSource="{StaticResource DesignSource}">
            </TreeView>
        </ContentControl>
        <!--Browser to view the feed content-->
        <WebBrowser x:Name="FeedWebBrowser"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    Grid.Row="1"
                    Grid.Column="1" />
        <!--Separate the web browser and TreeView and allows resizing of both-->
        <GridSplitter HorizontalAlignment="Right"
                      VerticalAlignment="Stretch"
                      Width="3"
                      Grid.Row="1" />
    </Grid>

</Window>